package com.cyh.testscrollviewrecyclerview.test1;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;


import com.cyh.testscrollviewrecyclerview.R;

import java.util.List;


public class FirstAdapter extends RecyclerView.Adapter{
    List<String> mData;
    public FirstAdapter(List<String> data) {
        mData = data;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if(viewType == 1) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.first_item, parent, false);
            return new VHolder(view);
        }
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        if (holder instanceof VHolder) {
            ((VHolder)holder).bindData(position);
        }
    }

    @Override
    public int getItemCount() {
        if(mData == null) {
            return 0;
        }
        return mData.size();
    }

    @Override
    public int getItemViewType(int position) {
        return 1;
    }


    class VHolder extends RecyclerView.ViewHolder{

        TextView tv_title;



        public VHolder( View itemView) {
            super(itemView);
            tv_title = itemView.findViewById(R.id.tv_item_first);
        }

        public void bindData(int position) {
            tv_title.setText(mData.get(position));
        }
    }
}
